package com.better.frontend.controller.studentScore;

import com.better.backend.dataComputingService.model.stuScore.ExamStudentScoreCalModel;
import com.better.backend.mqReceiverService.studentRecever.model.ScoreReceverModel;
import com.better.common.base.ServiceResponse;
import com.better.common.utils.ServiceResponseHandle;
import com.better.frontend.Iservice.studentScore.StudentScoreService;
import com.better.frontend.model.studentScore.ScoreAyalysModel;
import com.better.frontend.model.studentScore.ScoreParam;
import com.better.frontend.model.studentScore.StuCompModel;
import com.better.frontend.vo.studentScore.ScoreAnaySizeParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 成绩分析管理接口
 * Created by wfm on 2017/11/11.
 */
@RestController
@RequestMapping("/api/exam")
@Api(value = "成绩分析管理", tags = {"成绩分析管理接口"})
public class ScoreManagerController {
    @Autowired
    private StudentScoreService studentScoreService;

    /**
     * 查看成绩
     * 根据考试信息，查询成绩信息
     *
     * @param scoreParam examId 考试ID必填，学校ID必填（）
     **/
    @ApiOperation(value = "查看成绩", notes = "查看成绩接口")
    @RequestMapping(value = "/checkscore", method = RequestMethod.POST)
    public ServiceResponse<?> checkscore(@RequestBody ScoreParam scoreParam) {
        ExamStudentScoreCalModel scoreModel = new ExamStudentScoreCalModel();
        BeanUtils.copyProperties(scoreParam, scoreModel);
        return ServiceResponseHandle.success(studentScoreService.getStudentScore(scoreModel, scoreParam.getPageIndex(), scoreParam.getPageSize()));
    }

    /**
     * 学生成绩分析
     *
     * @author:
     * @date :2017/11/18
     */
    @ApiOperation(value = "查看个人分析", notes = "个人成绩分析信息：考试ID+学生ID必填")
    @RequestMapping(value = "/scoreAyalys", method = RequestMethod.POST)
    @Cacheable(value = "studentScoreAyalys", keyGenerator = "keyGenerator")
    public ServiceResponse<?> studentScoreAyalys(@RequestBody @Valid ScoreAyalysModel scoreAyalysModel) {
        return ServiceResponseHandle.success(studentScoreService.getScoreAyalyse(scoreAyalysModel));
    }


    /**
     * 学生历次排名走势
     *
     * @author:
     * @date :2017/11/18
     */
    @ApiOperation(value = "学生历次排名走势", notes = "学生历次排名走势：考试ID+学生ID必填")
    @RequestMapping(value = "/StuComper", method = RequestMethod.POST)
    public ServiceResponse<?> StuComper(@RequestBody StuCompModel compModel) {
        return studentScoreService.getCompareExam(compModel);
    }

    /**
     * 学生历次单科成绩走势
     *
     * @author:
     * @date :2017/11/18
     */
    @ApiOperation(value = "学生历次单科成绩走势", notes = "学生历次单科成绩走势：考试ID+学生ID必填")
    @RequestMapping(value = "/StuComperBySubject", method = RequestMethod.POST)
    public ServiceResponse<?> StuComperBySubject(@RequestBody StuCompModel compModel) {
        return studentScoreService.StuComperBySubject(compModel);
    }

    /**
     * 上传学生成绩信息
     *
     * @param excelFile
     * @param scoreReceverModel
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "导入学生成绩", notes = "上传学生成绩信息")
    @PostMapping(value = "/uploadScore")
    public ServiceResponse uploadScore(MultipartFile excelFile, ScoreReceverModel scoreReceverModel) throws Exception {
        return this.studentScoreService.addScoreReceverModel(scoreReceverModel, excelFile);
    }

    /**
     * 查询考试导入详情
     *
     * @param examId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "查询考试导入详情", notes = "查询考试导入详情")
    @RequestMapping(value = "/ListSubjectDetails", method = RequestMethod.GET)
    public ServiceResponse ListSubjectDetails(String examId) {
        return studentScoreService.ListSubjectDetails(examId);
    }

    /**
     *  判断是否计算完成
     * @param examId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "判断是否计算完成", notes = "判断是否计算完成")
    @RequestMapping(value = "/finishCal", method = RequestMethod.GET)
    public ServiceResponse finishCal(String examId){
        return studentScoreService.finishCal(examId);
    }

    /**
     *  成绩导入详情
     * @param examId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "成绩导入详情", notes = "成绩导入详情")
    @RequestMapping(value = "/importDetails", method = RequestMethod.GET)
    public ServiceResponse importDetails(String examId,String classId,String subjectId){
        return studentScoreService.importDetails(examId,classId,subjectId);
    }

    /**
     *  发布成绩
     * @param examId
     * @return
     */
    @ApiOperation(value = "发布成绩", notes = "发布成绩")
    @RequestMapping(value = "publishScore",method = RequestMethod.GET)
    public ServiceResponse publishScore(String examId){
        return this.studentScoreService.publishScore(examId);
    }

    /**
     *  分数段个人分析
     * @param scoreParam
     * @return
     */
    @ApiOperation(value = "分数段个人分析", notes = "分数段个人分析")
    @PostMapping(value = "scoreAnalysis")
    public ServiceResponse scoreAnalysis(@RequestBody ScoreAnaySizeParam scoreParam){
        return this.studentScoreService.scoreAnalysis(scoreParam);
    }
    /**
     *  踩线生个人分析
     * @param scoreParam
     * @return
     */
    @ApiOperation(value = "踩线生个人分析", notes = "踩线生个人分析")
    @PostMapping(value = "footAnalysis")
    public ServiceResponse footAnalysis(@RequestBody ScoreAnaySizeParam scoreParam){
        return this.studentScoreService.footAnalysis(scoreParam);
    }


}
